const app = getApp()
const userService = require('../../services/userService');

Component({
	data: {
		assets:app.assets,
		assetsByEnv:app.assetsByEnv,
		messageNum: 0,
		indexActive: true,
		msgActive: false,
		tabBarList: [{
		  "pagePath": "/pages/allianceIndex/allianceIndex",
		  "text": "商家联盟",
		  type: 'url',
		},
		{
		  "pagePath": "/pages/allianceMessageList/allianceMessageList",
		  "text": "消息",
		  type: 'message',
		}]
	},
	ready: function() {
		// this.getNavRemind()
		this.setData({
			indexActive: app.globalData.indexActive,
			msgActive: app.globalData.msgActive
		})
	},
	methods: {
		getNavRemind: function () {
			var user = wx.getStorageSync('user');
	    if(user && user.openid) {
	      userService.getNavRemind({openid:user.openid,project_type:4}).then((data) => {
	        if(data.code == 1) {
	          var msg_unread_num = data.data.msg_unread_num;
	          if(msg_unread_num > 99) {
	            this.setData({
	            	messageNum: 'N'
	            })
	          } else {
	          	this.setData({
	            	messageNum: msg_unread_num
	            })
	          }
	        } else {
						wx.showToast({
             	title:data.msg,
             	icon:'none'
            });
	        }
				}, (error) => {
					wx.showToast({
						title: 'getNavRemind接口异常' + error,
						icon:'none'
					});
				});
			} else {
				console.log('未获到用户openid');
			}
		},
		tapIndex: function() {
			app.globalData.indexActive = true,
			app.globalData.msgActive = false
		},
		tapMsg: function() {
			app.globalData.indexActive = false,
			app.globalData.msgActive = true
		}
	}
})